# -*- coding:utf-8 -*-
from __future__ import unicode_literals

from django.contrib import admin

from wlmodels.codes.utils import ELBaseAdmin, EntIdableAdmin
from .models import *


class ELPatentEntInline(admin.StackedInline):
    model = ELPatentEnt
    extra = 1
    raw_id_fields = ("pid",)


class ELPatentAdmin(ELBaseAdmin):
    list_display = ["pid", "patname", "sqh", "sqr", "sqrq", ]
    list_display_links = ["patname", ]
    search_fields = ("^patname",)
    readonly_fields = ["pid", ]
    inlines = (ELPatentEntInline,)


class ELCopyrightSoftwareAdmin(ELBaseAdmin):
    list_display = ["id", "softname", "regno_software", "classno_software", "softname_full", ]
    list_display_links = ["softname", ]
    search_fields = ("^softname",)


class ELCopyrightProductionAdmin(ELBaseAdmin):
    list_display = ["id", "prodname", "regno_production", "regdate_production", "class_production", ]
    list_display_links = ["prodname", ]
    search_fields = ("^prodname",)


class ELIcpregAdmin(ELBaseAdmin):
    list_display = ["id", "regno_ICP", "name_ICP", "type_ICP", "webname_ICP", ]
    list_display_links = ["regno_ICP", ]
    search_fields = ("^regno_ICP",)


class ELTminfoAdmin(EntIdableAdmin):
    list_display = ["id", "entid_id", "TMApplicant", "RegNO", "TMCN", "IntCls", "AppDate"]
    list_display_links = ["TMApplicant", ]


class ELTmflowAdmin(ELBaseAdmin):
    list_display = ["id", "RegNO", "FlowName", "FlowDate", ]
    list_display_links = ["RegNO", ]
    search_fields = ("^RegNO",)


class ELBidAdmin(EntIdableAdmin):
    list_display = ["id", "entid", "title", "case_type", "pubdate"]
    list_display_links = ["entid", "title", ]


class ELLandAdmin(EntIdableAdmin):
    list_display = ["id", "entid", "item_id", "case_type", "pubdate"]
    list_display_links = ["entid", ]


class ELNewsAdmin(EntIdableAdmin):
    list_display = ["id", "entid", "ENTNAME", "title", "srcurl", "ntype", "posttime", ]
    list_display_links = ["entid", "ENTNAME", ]
    list_filter = ["ntype", ]


class ELJobCompanyAdmin(EntIdableAdmin):
    list_display = ["id", "entid", "tyid", "name", "first_run", "last_run", ]
    list_display_links = ["entid", ]


class ELJobInfoAdmin(EntIdableAdmin):
    list_display = ["id", "entid", "tyid", "job_title", "first_run", "last_run", ]
    list_display_links = ["entid", ]


class ELDegreeinfoAdmin(ELBaseAdmin):
    list_display = ["id", "name", "gradschool", "graddate", "educdegree", ]
    list_display_links = ["name", ]
    search_fields = ("^name",)


#########################
####### 各种统计信息 #######
#########################


class ELStatisticsEntMonthAdmin(ELBaseAdmin):
    list_display = ["id", "tmonth", "region_id", "nic_id", "newent", "cancelent", "revokeent", "updated"]
    list_filter = ["tmonth", ]
    readonly_fields = ("updated",)


class ELStatisticsTaxAdmin(ELBaseAdmin):
    list_display = ["id", "year", "region_id", "nic_id", "revenue", "total_profit", "assets", "updated"]
    list_filter = ["year", ]
    readonly_fields = ("updated",)


class ELStatisticsHGAdmin(ELBaseAdmin):
    list_display = ["id", "region_id", "nic_id", "timport", "texport", "updated"]
    list_filter = ["tmonth", ]
    readonly_fields = ("updated",)


class ELStatisticsEntAdmin(ELBaseAdmin):
    list_display = ["id", "tmonth", "region_id", "nic_id", "companytype", "ENTSTATUS", "count", "updated"]
    list_filter = ["tmonth", "companytype", "ENTSTATUS", ]
    readonly_fields = ("updated",)


class ELCountAdmin(admin.ModelAdmin):
    list_display = ["id", "name", "table", "count", "updated"]
    readonly_fields = ("updated",)
    ordering = ["-count", ]


class ELStatisticsCreditAdmin(ELBaseAdmin):
    list_display = ["id", "year", "region_name", "nic_name", "index_total", ]
    list_display_links = ["year", ]


admin.site.register(ELPatent, ELPatentAdmin)
admin.site.register(ELCopyrightSoftware, ELCopyrightSoftwareAdmin)
admin.site.register(ELCopyrightProduction, ELCopyrightProductionAdmin)
# admin.site.register(ELIcpreg, ELIcpregAdmin)
admin.site.register(ELTminfo, ELTminfoAdmin)
# admin.site.register(ELTmflow, ELTmflowAdmin)
# admin.site.register(ELBid, ELBidAdmin)
# admin.site.register(ELLand, ELLandAdmin)
# admin.site.register(ELNews, ELNewsAdmin)
# admin.site.register(ELJobCompany, ELJobCompanyAdmin)
# admin.site.register(ELJobInfo, ELJobInfoAdmin)
# admin.site.register(ELDegreeinfo, ELDegreeinfoAdmin)
# admin.site.register(ELStatisticsEntMonth, ELStatisticsEntMonthAdmin)
# admin.site.register(ELStatisticsTax, ELStatisticsTaxAdmin)
# admin.site.register(ELStatisticsHG, ELStatisticsHGAdmin)
# admin.site.register(ELStatisticsEnt, ELStatisticsEntAdmin)
# admin.site.register(ELCount, ELCountAdmin)
# admin.site.register(ELStatisticsCredit, ELStatisticsCreditAdmin)
